#include "fpsmeasurer.h"

#include <time.h>
#include "consoleoutput.h"

FPSMeasurer::FPSMeasurer(void) :
	accumulatedMilliseconds( 0 ),
	numberOfMeasurements( 0 ),
	lastMeasurementMilliseconds( GetTickCount() )
{
}


FPSMeasurer::~FPSMeasurer(void)
{
}

void FPSMeasurer::measure()
{
	DWORD currMeasurementMilliseconds = GetTickCount();
	accumulatedMilliseconds += currMeasurementMilliseconds - lastMeasurementMilliseconds;
	lastMeasurementMilliseconds = currMeasurementMilliseconds;
	numberOfMeasurements++;
}

void FPSMeasurer::print()
{
	if( numberOfMeasurements == 0 )
		CONSOLE( "no measurements made.")
	else
	{
		CONSOLE( "FPS: " << 1000.0f / ( ( (float) accumulatedMilliseconds ) / ( ( float ) numberOfMeasurements ) ) );
		accumulatedMilliseconds = 0;
		numberOfMeasurements = 0;
	}
}
